package public

import (
	"NovelBook/logic/book"
	"NovelBook/utils/response"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

// SearchFaintly 书名模糊查找
//
//	@Summary		书名模糊查找
//	@Description	根据书名进行模糊查找
//	@Tags			Public
//	@Accept			json
//	@Produce		json
//	@Param			wd	query		string								true	"书名关键字"
//	@Success		200	{object}	msg.Code1000{data=[]models.Books}	"返回书籍`Books`在`data`字段中"
//	@Failure		503	{object}	msg.Code1003						"系统繁忙，请稍后再试"
//	@Router			/public/book/search [get]
func SearchFaintly(c *gin.Context) {
	query := c.Query("wd")
	books, err := book.SearchFaintly(query)
	if err != nil {
		log.Println(err)
		response.FailWithMsg(c, http.StatusServiceUnavailable, response.CodeSystemBusy, "database error")
		return
	}
	response.Success(c, books)
	return
}
